package com.putao.album.collection;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.putao.album.R;
import com.putao.album.base.PtBaseAdapter;
import com.putao.album.collection.bean.CollectionItem;
import com.putao.album.util.BitmapHelper;
import com.putao.album.util.StringHelper;

import java.util.List;

/**
 * Created by chen on 15-5-5.
 */
public class CollectionAdapter extends PtBaseAdapter {


    public CollectionAdapter(Context context, List<CollectionItem> datalist) {
        super(context, datalist);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_collection_item, null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
            viewHolder.tips_kiss = (ImageView) convertView.findViewById(R.id.tips_kiss);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        CollectionItem item = (CollectionItem) getItem(position);

        DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(BitmapHelper.getLoadingDrawable()).showImageOnFail(BitmapHelper.getLoadingDrawable())
                .considerExifParams(true).cacheInMemory(true).cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(item.getPhoto(), viewHolder.imageView, options);

        if (item.getIs_praise() > 0) {
            viewHolder.tips_kiss.setVisibility(View.VISIBLE);
        } else {
            viewHolder.tips_kiss.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }

    class ViewHolder {
        public ImageView imageView;
        public ImageView tips_kiss;
    }
}
